//
//  RestaurantViewController.m
//  南京大牌档
//
//  Created by student on 13-12-25.
//  Copyright (c) 2013年 无锡第三团队. All rights reserved.
//

#import "RestaurantViewController.h"
#import "RestaurantCell.h"
#import "EveryRestaurantViewController.h"
#import "Reachability.h"
#import "ODRefreshControl.h"
@interface RestaurantViewController ()
{
    RestaurantCell *cell;
    
}
@end

@implementation RestaurantViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
            }
    return self;
}

- (void)viewDidLoad
{
	
    [super viewDidLoad];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
    }
#endif

    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationItem.title=@"附近:大牌档";
    UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
    temporaryBarButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    
      [self loadListView];
    activityIV = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [activityIV setCenter:CGPointMake(160, WXHLApplicationBounds().size.height/3)];
    [listView addSubview:activityIV];
    [activityIV startAnimating];
    if([CLLocationManager locationServicesEnabled] == NO){
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请开启定位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
    }
    else{
        
        locationManager=[[CLLocationManager alloc]init];
        locationManager.delegate = self;
        [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
        [locationManager startUpdatingLocation];
       
        
    }

}


- (void)loadListView
{
 
    

    listView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, 320,WXHLApplicationBounds().size.height) style:UITableViewStylePlain];

    listView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    listView.dataSource =self;
    listView.delegate =self;
    
    [self.view addSubview:listView];
     [self loadListData];
    mylocationLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
    
    mylocationLabel.backgroundColor=[UIColor clearColor];
    mylocationLabel.font=[UIFont systemFontOfSize:10];
    listView.tableHeaderView=mylocationLabel;
    ODRefreshControl *refreshControl = [[ODRefreshControl alloc] initInScrollView:listView];
    [refreshControl addTarget:self action:@selector(dropViewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];

    
}

- (void)dropViewDidBeginRefreshing:(ODRefreshControl *)refreshControl
{
    


    double delayInSeconds = 3.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        
        if([CLLocationManager locationServicesEnabled] == NO){
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请开启定位" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
        }
        else{
            
            locationManager=[[CLLocationManager alloc]init];
            locationManager.delegate = self;
            [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
            [locationManager startUpdatingLocation];
        
        }
        [refreshControl endRefreshing];
    });
    
    
}

-(void)loadListData
{
    /*
http://maps.google.com/maps/api/geocode/json?latlng=31.489687,120.366390&sensor=false
    德基广场南京大牌档32.04200，118，78456
    鼓楼区狮子桥 32.06743，118.77815
    南京大牌档河西龙江店32.05867   118.74259
    南京大牌档中山陵 32.04038   118.83594
    南京国际广场店32.07274  118.78340
    南京大牌档夫子庙平江府店 32.02083  118.79273
    南京大牌档(夫子庙水平方店) 32.02423 118.79157
    南京大牌档(江宁万达店) 31。95051 118.84502
    
    南京大牌档(世茂百货店)39.93419 116.44940
    南京大牌档(西直门凯德店)39.94189  116.35282
    南京大牌档(中关村店)39.98278  116.31329
    南京大牌档(崇文门国瑞店)39.89925 116.42327
    南京大牌档(凯德晶品店) 39.90810 116.29746
    */
   

    
    
    CLLocation *current=[[CLLocation alloc] initWithLatitude:coor2D.latitude longitude:coor2D.longitude];
    
    CLLocation *djLocation=[[CLLocation alloc] initWithLatitude:32.04200 longitude:118.78456];
    CLLocationDistance djDistance=[current distanceFromLocation:djLocation];
    
    CLLocation *szqLocation=[[CLLocation alloc] initWithLatitude:32.06743 longitude:118.77815];
    CLLocationDistance szqDistance=[current distanceFromLocation:szqLocation];
    
    CLLocation *ljLocation=[[CLLocation alloc] initWithLatitude:32.05867 longitude:118.74259];
    CLLocationDistance ljDistance=[current distanceFromLocation:ljLocation];
    
    CLLocation *zslLocation=[[CLLocation alloc] initWithLatitude:32.04038 longitude:118.83594];
    CLLocationDistance zslDistance=[current distanceFromLocation:zslLocation];
    
    CLLocation *gjgcLocation=[[CLLocation alloc] initWithLatitude:32.07274 longitude:118.78340];
    CLLocationDistance gjgcDistance=[current distanceFromLocation:gjgcLocation];
    
    CLLocation *pjfLocation=[[CLLocation alloc] initWithLatitude:32.02083 longitude:118.79273];
    CLLocationDistance pjfDistance=[current distanceFromLocation:pjfLocation];
    
    CLLocation *spfLocation=[[CLLocation alloc] initWithLatitude:32.02423 longitude:118.79157];
    CLLocationDistance spfDistance=[current distanceFromLocation:spfLocation];
    
    CLLocation *jlwdLocation=[[CLLocation alloc] initWithLatitude:31.95051 longitude:118.84502];
    CLLocationDistance jlwdDistance=[current distanceFromLocation:jlwdLocation];
    
    CLLocation *smbhLocation=[[CLLocation alloc] initWithLatitude:39.93419 longitude:116.44940];
    CLLocationDistance smbhDistance=[current distanceFromLocation:smbhLocation];
    
    CLLocation *xzmLocation=[[CLLocation alloc] initWithLatitude:39.94189 longitude:116.35282];
    CLLocationDistance xzmDistance=[current distanceFromLocation:xzmLocation];
    
    CLLocation *zgcLocation=[[CLLocation alloc] initWithLatitude:39.98278 longitude:116.31329];
    CLLocationDistance zgcDistance=[current distanceFromLocation:zgcLocation];
    
    CLLocation *grLocation=[[CLLocation alloc] initWithLatitude:39.89925 longitude:116.42327];
    CLLocationDistance grDistance=[current distanceFromLocation:grLocation];
    
    CLLocation *kdjpLocation=[[CLLocation alloc] initWithLatitude:39.90810 longitude:116.29746];
    CLLocationDistance kdjpDistance=[current distanceFromLocation:kdjpLocation];
    
    
    
    NSDictionary *djDic=@{@"title": @"南京德基广场店",@"address":@"地址:秦淮区中山路18号德基广场购物中心7楼",@"img":@"dj.jpg",@"distance":[NSNumber numberWithFloat:djDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:10:30-22:30\n",@" 乘地铁1、2号线 至新街口站下  从7号口出站",@" ☞ KTV\n ☞ 电影院\n ☞ 购物商场\n ☞ 洗浴中心",@" 德基地下停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"dj1.jpg",@"dj2.jpg",@"dj3.jpg",@"dj4.jpg",@"dj5.jpg",@"dj6.jpg",@"dj7.jpg",@"dj8.jpg",@"dj9.jpg",@"dj10.jpg",nil]};
    
    NSDictionary *szqDic=@{@"title": @"南京狮子桥店",@"address":@"地址:鼓楼区湖南路狮子桥2号湖南路步行街内",@"img":@"szq.jpg",@"distance":[NSNumber numberWithFloat:szqDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-24:00\n 周六至周日:10:30-24:00\n",@" 乘3路、8路、22路、26路、47路、52路、56路、114路、819路到玄武湖公园（湖南路）站下",@" ☞ KTV\n ☞ 电影院\n ☞ 公园\n ☞ 美食街",@" 狮子桥停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"szq1.jpg",@"szq2.jpg",@"szq3.jpg",@"szq4.jpg",@"szq5.jpg",@"szq6.jpg",@"szq7.jpg",@"szq8.jpg",@"szq9.jpg",@"szq10.jpg",nil]};
    
    NSDictionary *ljDic=@{@"title": @"南京龙江店",@"address":@"地址:鼓楼区草场门大街96号中青大厦1楼(近龙江体育馆)",@"img":@"lj.jpg",@"distance":[NSNumber numberWithFloat:ljDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@" 公交车91、57、150、32、127、317、11、66、45、游4都可以到达",@" ☞ KTV\n ☞ 大型超市\n",@" 附近免费停车场",@" 常年八折优惠",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水\n ☞ 无需排队",nil],@"imageArray":[NSArray arrayWithObjects:@"lj1.jpg",@"lj2.jpg",@"lj3.jpg",@"lj4.jpg",@"lj5.jpg",@"lj6.jpg",@"lj7.jpg",@"lj8.jpg",@"lj9.jpg",@"lj10.jpg",nil]};
    
    NSDictionary *zslDic=@{@"title": @"南京中山陵店",@"address":@"地址:中山陵陵园路2号(近中山陵风景区)",@"img":@"zsl.jpg",@"distance":[NSNumber numberWithFloat:zslDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:00\n 周六至周日:11:00-21:00\n",@" 地铁二号线苜蓿园站1号出口",@" ☞ 公园",@" 免费停车",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水\n ☞ 无需排队",nil],@"imageArray":[NSArray arrayWithObjects:@"zsl1.jpg",@"zsl2.jpg",@"zsl3.jpg",@"zsl4.jpg",@"zsl5.jpg",@"zsl6.jpg",@"zsl7.jpg",@"zsl8.jpg",@"zsl9.jpg",@"zsl.jpg",nil]};
    
    NSDictionary *gjgcDic=@{@"title": @"南京国际广场店",@"address":@"地址:鼓楼区中央路201号南京国际广场7楼(近玄武湖公园)",@"img":@"gjgc.jpg",@"distance":[NSNumber numberWithFloat:gjgcDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@" 地铁1号线玄武门站 1号出口",@" ☞ KTV\n ☞ 公园\n ☞ 电影院\n ☞ 综合商场",@" 国际广场地下停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"gj2.jpg",@"gjgc.jpg",@"gj3.jpg",@"gj4.jpg",@"gj5.jpg",@"gj6.jpg",@"gj7.jpg",@"gj8.jpg",@"gj9.jpg",@"gj10.jpg",nil]};
    
    NSDictionary *pjfDic=@{@"title": @"南京夫子庙平江府店",@"address":@"地址:秦淮区大石坝街48号",@"img":@"pjf.jpg",@"distance":[NSNumber numberWithFloat:pjfDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:10:30-22:00\n",@" 地铁1号线三山街站下",@" ☞ KTV\n ☞ 步行街\n ☞ 公园",@" 附近停车场",@" 新店大酬宾",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水\n ☞ 无需排队",nil],@"imageArray":[NSArray arrayWithObjects:@"fzm1.jpg",@"fzm2.jpg",@"fzm3.jpg",@"fzm4.jpg",@"fzm5.jpg",@"fzm6.jpg",@"fzm7.jpg",@"fzm8.jpg",@"fzm9.jpg",@"fzm10.jpg",nil]};
    
    NSDictionary *spfDic=@{@"title": @"南京夫子庙水平方店",@"address":@"地址:秦淮区建康路3号水平方6楼",@"img":@"spf.jpg",@"distance":[NSNumber numberWithFloat:spfDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@" 地铁1号线三山街站下",@" ☞ KTV\n ☞ 公园\n ☞ 购物商场",@" 附近停车场",@" 新店大酬宾",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水\n ☞ 无需排队",nil],@"imageArray":[NSArray arrayWithObjects:@"spf1.jpg",@"spf2.jpg",@"spf3.jpg",@"spf4.jpg",@"spf5.jpg",@"spf6.jpg",@"spf7.jpg",@"spf8.jpg",@"spf9.jpg",@"spf10.jpg",nil]};
    
    NSDictionary *jlwdDic=@{@"title": @"南京江宁万达店",@"address":@"地址:江宁区东山街道竹山路59号万达广场4楼",@"img":@"jlwd.jpg",@"distance":[NSNumber numberWithFloat:jlwdDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@" 地铁1号线中国药科大学方向竹山路下",@" ☞ KTV\n ☞ 电影院\n ☞ 购物商场\n ☞ 洗浴中心",@" 万达地下停车场\n 收银台领取免费停车券",@" 新店大酬宾",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水\n ☞ 无需排队",nil],@"imageArray":[NSArray arrayWithObjects:@"jnwd1.jpg",@"jnwd2.jpg",@"jnwd3.jpg",@"jnwd4.jpg",@"jnwd5.jpg",@"jnwd6.jpg",@"jnwd7.jpg",@"jnwd8.jpg",@"jnwd9.jpg",@"jnwd10.jpg",nil]};
    
    NSDictionary *smbhDic=@{@"title": @"北京世贸百货店",@"address":@"地址:朝阳区工体北路13号世茂百货4楼",@"img":@"smbh.jpg",@"distance":[NSNumber numberWithFloat:smbhDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@"  ",@" ☞ KTV\n ☞ 电影院\n ☞ 购物商场",@" 地下停车场\n 收银台领取免费停车券",@" 大众点评网会员专享9.5折优惠",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"bjsmbh1.jpg",@"bjsmbh2.jpg",@"bjsmbh3.jpg",@"bjsmbh4.jpg",@"bjsmbh5.jpg",@"bjsmbh6.jpg",@"bjsmbh7.jpg",@"bjsmbh8.jpg",@"bjsmbh9.jpg",@"bjsmbh10.jpg",nil]};
    
    NSDictionary *xzmDic=@{@"title": @"北京西直门凯德店",@"address":@"地址:西城区西直门外大街1号凯德MALL购物中心5楼",@"img":@"xzm.jpg",@"distance":[NSNumber numberWithFloat:xzmDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@"  ",@" ☞ KTV\n ☞ 购物商场",@" 凯德mall地下停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"bjxzm1.jpg",@"bjxzm2.jpg",@"bjxzm3.jpg",@"bjxzm4.jpg",@"bjxzm5.jpg",@"bjxzm6.jpg",@"bjxzm7.jpg",@"bjxzm8.jpg",@"bjxzm9.jpg",@"bjxzm10.jpg",nil]};
    
    NSDictionary *zgcDic=@{@"title": @"北京中关村店",@"address":@"地址:海淀区海淀大街5号中关村广场购物中心D区津乐汇2楼(近鼎好大厦)",@"img":@"zgc.jpg",@"distance":[NSNumber numberWithFloat:zgcDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@"  ",@" ☞ KTV\n ☞ 电影院\n ☞ 电子商场",@" 地下停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"bjzgc1.jpg",@"bjzgc2.jpg",@"bjzgc3.jpg",@"bjzgc4.jpg",@"bjzgc5.jpg",@"bjzgc6.jpg",@"bjzgc7.jpg",@"bjzgc8.jpg",@"bjzgc9.jpg",@"zgc.jpg",nil]};
    
    NSDictionary *grDic=@{@"title": @"北京崇文门国瑞店",@"address":@"地址:北京市东城区崇文门外大街18号国瑞购物中心3层",@"img":@"gr.jpg",@"distance":[NSNumber numberWithFloat:grDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00\n",@"  ",@" ☞ KTV\n ☞ 电影院\n ☞ 购物商场",@" 商场地下停车场\n 收银台领取免费停车券",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"bjcwmg1.jpg",@"bjcwmg2.jpg",@"bjcwmg3.jpg",@"bjcwmg4.jpg",@"bjcwmg5.jpg",@"bjcwmg6.jpg",@"bjcwmg7.jpg",@"bjcwmg8.jpg",@"bjcwmg9.jpg",@"bjcwmg10.jpg",nil]};
    
    NSDictionary *kdjpDic=@{@"title": @"北京凯德晶品店",@"address":@"地址:西城区西直门外大街1号凯德MALL购物中心5楼",@"img":@"kdjp.jpg",@"distance":[NSNumber numberWithFloat:kdjpDistance],@"array":[NSArray arrayWithObjects:@" 周一至周五:11:00-14:00 17:00-21:30\n 周六至周日:11:00-22:00",@"  ",@" ☞ KTV\n ☞ 电影院\n ☞ 综合商场",@" 地下停车场免费",@" 暂无",@" ☞ 支持刷卡\n ☞ 无最低消费\n ☞ 谢绝自带酒水",nil],@"imageArray":[NSArray arrayWithObjects:@"bjkdjp1.jpg",@"bjkdjp2.jpg",@"bjkdjp3.jpg",@"bjkdjp4.jpg",@"bjkdjp5.jpg",@"bjkdjp6.jpg",@"bjkdjp7.jpg",@"bjkdjp8.jpg",@"bjkdjp9.jpg",@"bjkdjp10.jpg",nil]};
    
    
    
    listArray=[[NSMutableArray alloc]initWithObjects:djDic,szqDic,ljDic,zslDic,gjgcDic, pjfDic,spfDic,jlwdDic,smbhDic,xzmDic,zgcDic,grDic,kdjpDic,nil];
    
    NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES]];
    [listArray sortUsingDescriptors:sortDescriptors];

}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    coor2D=newLocation.coordinate;
     [manager stopUpdatingLocation];
    NSLog(@"1111");
//    if (WXHLOSVersion()>=7.0) {
//        listView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, WXHLApplicationBounds().size.height-64-49) style:UITableViewStylePlain];
//    }
//    else{
//        listView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320,WXHLApplicationBounds().size.height-64-49) style:UITableViewStylePlain];
//    }
    [listView removeFromSuperview];
//     listView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, WXHLApplicationBounds().size.height-64-49) style:UITableViewStylePlain];
    
    [self loadListView];
    
    Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    if ([r currentReachabilityStatus]==NotReachable) {
        mylocationLabel.text=@"无法解析您当前的位置，请确认是否联网，下拉刷新";
    }
    else{
        NSError *error;
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",coor2D.latitude,coor2D.longitude]]];
        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        
        NSDictionary *locationDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
        if ([[locationDic objectForKey:@"status"]isEqualToString:@"ZERO_RESULTS"]) {
            mylocationLabel.text=@"无法解析您当前的位置，请确认是否联网，下拉刷新";
            
        }
        else{
            mylocationLabel.text=[NSString stringWithFormat:@"当前位置:%@",[[locationDic objectForKey:@"results"][0] objectForKey:@"formatted_address"]];
        }

        
    }
   [activityIV stopAnimating];
   
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    [listView removeFromSuperview];
    CLLocation *currentLocation = [locations lastObject];
    coor2D=currentLocation.coordinate;
    [manager stopUpdatingLocation];
    
    if (WXHLOSVersion()>=7.0) {
        listView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, WXHLApplicationBounds().size.height-64-49) style:UITableViewStylePlain];
    }
    else{
        listView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320,WXHLApplicationBounds().size.height-64-49) style:UITableViewStylePlain];
    }

    [self loadListView];
    Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    if ([r currentReachabilityStatus]==NotReachable) {
        mylocationLabel.text=@"无法解析您当前的位置，请确认是否联网，下拉刷新";
    }
    else{
    NSError *error;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",coor2D.latitude,coor2D.longitude]]];
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    
    NSDictionary *locationDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
        
        if ([[locationDic objectForKey:@"status"]isEqualToString:@"ZERO_RESULTS"]) {
       mylocationLabel.text=@"无法解析您当前的位置，请确认是否联网，下拉刷新";
        
        }
        else{
            mylocationLabel.text=[NSString stringWithFormat:@"当前位置:%@",[[locationDic objectForKey:@"results"][0] objectForKey:@"formatted_address"]];
        }
    
    }
    [activityIV stopAnimating];
}

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 13;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *identifer=@"Cell";
    cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if(cell==nil)
    {
        cell=[[RestaurantCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    [cell.restaurantImage setImage:[UIImage imageNamed:[listArray[indexPath.row]objectForKey:@"img"]]];
    cell.titleLabel.text=[listArray[indexPath.row]objectForKey:@"title"];
    cell.addressLabel.text=[listArray[indexPath.row]objectForKey:@"address"];
    if ([[listArray[indexPath.row]objectForKey:@"distance"] floatValue]>1000) {
        cell.distanceLabel.text=[NSString stringWithFormat:@"距离:%d公里",(int)[[listArray[indexPath.row]objectForKey:@"distance"] floatValue]/1000];
    }
    else{
        cell.distanceLabel.text=[NSString stringWithFormat:@"距离:%d米",(int)[[listArray[indexPath.row]objectForKey:@"distance"] floatValue]];
    }
    
  
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EveryRestaurantViewController *erVC=[[EveryRestaurantViewController alloc]init];
    

    erVC.imageArray=[listArray[indexPath.row]objectForKey:@"imageArray"];
    erVC.distance=[listArray[indexPath.row]objectForKey:@"distance"];
    erVC.everyArray=[listArray[indexPath.row]objectForKey:@"array"];
    [erVC.navigationItem setTitle:[listArray[indexPath.row]objectForKey:@"title"]];
      [self.navigationController pushViewController:erVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
